﻿
@{
    ViewBag.Title = "小杨工具库";
    Layout = "~/Views/Shared/_MobileLayout.cshtml";
    var state = Request.QueryString["state"].xTrim().ToLower();
    var userid = Request.QueryString["userid"].xTrim();
    var code = Request.QueryString["code"].xTrim();

    if (string.IsNullOrWhiteSpace(code) && string.IsNullOrWhiteSpace(userid))
    {
        Html.RenderPartial("Result", new YYS.ResultModel() { IsPart = 1, Icon = 1, Msg = "加载中，请稍后...", AutoURL = $"https://open.weixin.qq.com/connect/oauth2/authorize?appid={YYS.DefaultValue.AppID_WXCS}&redirect_uri={YYS.DefaultValue.wxUrl}&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect" });
        return;
    }

    if (!string.IsNullOrWhiteSpace(code)&& string.IsNullOrWhiteSpace(userid))
    {
        var login=YYS.Controllers.HomeController.WxLogin(code);
        if (login.errcode != 0)
        {
            Html.RenderPartial("Result", new YYS.ResultModel() { IsPart = 1, Icon = 5, Msg = "登录失败："+ login.errmsg });
            return;
        }
        Html.RenderPartial("Result", new YYS.ResultModel() { IsPart = 1, Icon = 1, Msg = "加载中，请稍后...", AutoURL = Url.Action("go", "wx", new { state = "userinfo", userid = login.openid }) });
    }

    //var user = Request.v3UnifiedUser();
    var user = YYS.Controllers.pcController.v3getCurrentUser(userid, 2);

    if (user.HasError)
    {
        Html.RenderPartial("Result", new YYS.ResultModel() { IsPart = 1, Icon = 4, Msg = user.Error+"，openId："+userid, AutoURL = Url.Action("login", "wx", new { userid = userid }), AutoTimeout=3 });
        return;
    }

    if (string.IsNullOrWhiteSpace(state))
    {
        Html.RenderPartial("Result", new YYS.ResultModel() { IsPart = 1, Icon = 1, Msg = "加载中，请稍后...", AutoURL = Url.Action("go", "wx", new { state = "userinfo", userid = userid }) });
        return;
    }

    var access = user.Obj.wxMenus.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.state) && state.Equals(x.state, StringComparison.OrdinalIgnoreCase));
    if (access == null) //页面不存在
    {
        Html.RenderPartial("Result", new YYS.ResultModel() { IsPart = 1, Icon = 0, Msg = "您所请求的页面不存在", AutoURL = Url.Action("go", "wx", new { state = "userinfo", userid = userid }) });
        return;
    }
    var pageUrl = access.page;
}

<div id="wxApp" v-cloak class="flex-column hidden bg-white" style="max-width:800px; margin:0 auto;">
    <float-button v-if="showHome" :init-top="initTop" v-on:click="goHome">
        <i class="van-icon van-icon-wap-home-o" style="font-size:24px !important;"></i>
    </float-button>
    <van-cell-group v-if="showHeader" :border="false" class="shadow-1" style="margin-bottom:2px;">
        <van-cell center value-class="flex-none padding-left-15" :border="false" style="padding-right:0;">
            <template #icon>
                <div style="padding-right:10px;">
                    <van-image lazy-load width="50px" height="50px" fit="cover" round :src="optor.imgUrl" error-icon="contact" loading-icon="contact"></van-image>
                </div>
            </template>
            <template #title>
                <div style="font-size:13px;"><span style="font-size:14px;font-weight:bold;">{{optor.uiName}}</span>（{{optor.account}}）</div>
            </template>
            <template #label>
                {{optor.uiTime}}
            </template>
            <div class="padding-lr-10">
                <van-tag class="bg-redLight color-red" size="large" v-on:click="out">退出</van-tag>
            </div>
            
        </van-cell>
    </van-cell-group>
    <div class="flex-column-fill hidden">
        <div class="h100 hidden-x">
            <wx-page v-on:hook:mounted="loaded=true" ref="wxPage"></wx-page>
            @*<keep-alive>
                    <router-view v-on:hook:mounted="loaded=true" ref="wxPage"></router-view>
                </keep-alive>*@
            <van-empty v-if="!loaded" description="加载中，请稍后..."></van-empty>
        </div>
    </div>
    <hxt-popup v-model="downloadShow" :href="downloadHref" style="max-height:100%; height:100%;background-color:#000;">
        <div v-if="downloadShow" style="user-select:none; height:100%;width:100%; background-image:url('@(Request.v3JsCss("images/wxdownload.jpg"))'); background-repeat:no-repeat; background-size:contain; background-position:right top;" v-on:click="downloadShow=false"></div>
    </hxt-popup>
</div>


<div id="divLoading">
    <style>
        body {
            background-color: #FFF;
            background-image: none;
        }
    </style>
</div>
@section script{
    <script src="@(Request.v3JsCss("jweixin-1.6.0.js"))"></script>
    @*<script src="@(Request.v3JsCss("index/vue/vue-router.js"))"></script>*@
    <script src="@(Request.v3JsCss("index/vue/vxe-table/xe-utils.js"))"></script>
    <script src="@(Request.v3JsCss("index/vue/vxe-table/vxe-table.js"))"></script>
}
@section body{
    @System.Web.Optimization.Scripts.Render("~/Content/wx/index?rd=" + DateTime.Now.ToString())
<script type="text/javascript">
    window.$jscript.fn.wxApp.ready({
        optor: '@(user.Obj.xConvertObjectToJson(false).xToBase64())',
        components: { wxPage: '@(this.vueComponent(pageUrl).xToBase64())' },
        link: '@(Url.Content("~/"))'
    });
</script>
}

